var unitId = '';
var roleType;
//分页初始化
var pageNum = 1;
var pageSize = 10;
var total;
mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		down: { //下拉刷新
			callback: pulldownRefresh,
			style: mui.os.android ? "circle" : "default"
		},
		up: { //上拉加载
			contentinit: '',
			contentrefresh: '正在加载...',
			contentnomore: '没有更多了',
			callback: pullupRefresh,
		}
	}
});

mui.plusReady(function() {
	roleType = localStorage.getItem("roleType");
	self = plus.webview.currentWebview();
	unitId = self.info.unitId;
	getEquipList(unitId)

	//点击进入详情
	mui("#list_warp").on('tap', 'li', function() {
		var id = this.getAttribute("data-id");
		var equipName = this.querySelector('.title').innerText;
		var equipAdd = this.getAttribute("data-add");
		var equipModel = this.querySelector('.text-model').innerText;
		var equipAlarm = this.querySelector('.text-alarm').innerText;
		openNew("statisticsDetail.html", {
			equipName: equipName,
			equipAdd: equipAdd,
			equipModel: equipModel,
			equipAlarm: equipAlarm
		});
	})
})
//下拉刷新具体业务实现
function pulldownRefresh() {
	//重置页码
	pageNum = 1;
	getEquipList(unitId);
}
// 上拉加载具体业务实现
function pullupRefresh() {
	getEquipList(unitId, true);
}
// 统计评估-设备列表  （设备名称、设备型号、报警数）
function getEquipList(unitId, isnextpage, isreload) {
	if (isnextpage&&(pageNum * pageSize < total)) { //加载下一页
		pageNum++;
	} else if (isreload) { //重新加载当前页
		pageNum = curr_pageno;
	} else if (pageNum == 0) {
		pageNum = 1; //未加载过
	} else {
		pageNum = 1; //默认加载第一页
	}
	var showload = pageNum == 1;
	var isappend = pageNum > 1 ? true : false;
	log(pageNum + "," + total + "," + showload + "," + isappend)
	if (pageNum * pageSize >= total) {
		appPage.endPullRefresh(true);
	}
	
	request("/app/alarm/statistics/equipment/list", "GET",{
		unitId: unitId,
		roleType: roleType,
		pageNum: pageNum,
		pageSize: pageSize
	}, function(res) {
		pageNum = res.pager.pageNum;
		pageSize = res.pager.pageSize;
		total = res.pager.total;
		
		var nomore = true;
		if(res.code == 0) {
			render("#list_warp", "eqList", res, isappend);
			nomore = pageNum*pageSize >= total;
		} else {
			appUI.showTopTip(json.msg);
		}
	
		appPage.endPullRefresh(nomore);
	}, true, function() {
		appPage.endPullRefresh();
	});
}
